function tline = textline(ttext, starts, ends, lnum)
% textline  - one line from a multi-line 1xN char array
%
% FORMAT:       tline = textline(ttext, starts, ends, lnum)
%
% Input fields:
%
%       ttext       1xN char array
%       starts      1xN double array with line start positions
%       ends        1xN double array with line end positions
%       lnum        1x1 double, line number
%
% Output fields:
%
%       tline       line of text
%
% See also asciiread.

% Version:  v0.5c
% Build:    6120415
% Date:     Dec-04 2006, 3:15 PM CET
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 4 || ...
    length(size(start)) ~= length(size(ends)) || ...
    any(size(starts) ~= size(ends)) || ...
    isempty(lnum(:)) || ...
    lnum(1) > numel(starts) || ...
    lnum(1) < 1
    error( ...
        'BVQXtools:BadArgument', ...
        'Bad or missing argument.' ...
    );
end

% return textline
lnum = fix(lnum(1));
tline = ttext(starts(lnum):ends(lnum));
